/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package test;

import bean.business.accountBean;
import bean.business.classBean;
import bean.business.curriculumBean;
import bean.business.reEvaluationBean;
import bean.business.searcBean;
import bean.business.semesterBean;
import bean.business.stuDetailBean;
import bean.business.studentBean;
import entities.Classes;
import entities.Semester;
import entities.StuDetail;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author HoangHai
 */
@WebServlet(name = "t", urlPatterns = {"/t"})
public class t extends HttpServlet {
    @EJB
    private stuDetailBean stuDetailBean;

    @EJB
    private searcBean searcBean;
    @EJB
    private semesterBean semesterBean;
    @EJB
    private reEvaluationBean reEvaluationBean;
    @EJB
    private curriculumBean curriculumBean;
    @EJB
    private studentBean studentBean;
    @EJB
    private classBean classBean;
    @EJB
    private accountBean accountBean;

    /** 
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            /* TODO output your page here
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet t</title>");  
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Servlet t at " + request.getContextPath () + "</h1>");
            out.println("</body>");
            out.println("</html>");
             */
//            Account a = new Account();
//            //a.setAccID(5);
//            a.setAccName("ab");
//            a.setAccPass("123nngf");
//            a.setUserType(1);
//            accountBean.addAccount(a);
//            Account a = accountBean.findAccByID(1);
//            out.print(a.getAccName());
//            Student s = new Student();
//            Classes cl = classBean.findClassByID(1);
//            s.setStuID("GC010");
//            s.setStuName("bx");
//            s.setClassID(cl);
//            studentBean.updateStudent(s);
//            Curriculum c = curriculumBean.findCurByID(2);
//            out.print(c.getCuName());
//            curriculumBean.delCurriculum(2);
//            Account a = accountBean.findAccByID(1);
//            a.setAccPass("123");
//            accountBean.updateAccount(a);
//            List<Student> list = studentBean.allStudent();
//            out.print(list.size());
            //Curriculum c = curriculumBean.findCurByID(1);
//            List<Classes> list = classBean.findBySeID(1);
//            out.print(list.size());
//            Mark mark =  searcBean.findSemByID(1, "GC001");
//            mark.getMark();
           // StuDetail detail = stuDetailBean.findStuByClassIDandSubID(1, 1);
            //out.print(detail.getStuID());
            
//            List<StuDetail> as = stuDetailBean.findStuByStuIDandSubID("GC001", 1);
//                    out.println(as.size());
//            StuDetail detail = stuDetailBean.findByID(1);
//            detail.setMark(5.0);
//            stuDetailBean.updateStudentDetail(detail);
//            List<Semester> a = searcBean.findSemByClassID(1);
//            out.println(a.size());
            List<StuDetail> details = stuDetailBean.findByStuI("GC002");
            out.print(details.size());
//            List<Classes> b = searcBean.findClassIDandByStu("GC002");
//            out.println(b.size());
        } finally {
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
